package com.sky.shortlink.admin.controller;

import com.sky.shortlink.admin.convention.result.Result;
import com.sky.shortlink.admin.convention.result.Results;
import com.sky.shortlink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.sky.shortlink.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.sky.shortlink.admin.dto.resp.ShortLinkGroupUpdateDTO;
import com.sky.shortlink.admin.remote.dto.resp.ShortLinkGroupRespDTO;
import com.sky.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blue sky
 * @Description 短链接分组控制层
 * @create 2024-02-18 10:20
 */

@RestController
@RequiredArgsConstructor
@Slf4j
public class GroupController {
    private final GroupService groupService;

    /**
     * 新增短链接分组
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO saveReqDTO){
        groupService.saveGroup(saveReqDTO);
        return Results.success();
    }

    /**
     * 查询分组集合
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }

    /**
     * 修改短链接分组名
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateDTO updateDTO){
        groupService.updateGroup(updateDTO);
        return Results.success();
    }
    /**
     * 删除短链接分组
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam("gid") String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }

    /**
     * 排序短链接分组
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> SortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> list){
        groupService.SortGroup(list);
        return Results.success();
    }



}
